from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

DATABASE_URL = "mysql+mysqldb://root:root@localhost:3306/birds_users"

engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False,autoflush=False,bind=engine)

Base = declarative_base()

def get_db():
    try:
        # 尝试连接
        with engine.connect() as connection:
            print("数据库连接成功")
            return "数据库连接成功"
    except Exception as e:
        print(f"数据库连接失败: {e}")
        return "数据库连接失败"

#测试
# get_db()